package com.manage.dao;

import com.manage.domain.UserInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface IUserDao {

    @Select("select * from users where username=#{username}")
    @Results({
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "username", property = "username"),
            @Result(column = "email", property = "email"),
            @Result(column = "password", property = "password"),
            @Result(column = "phoneNum", property = "phoneNum"),
            @Result(column = "status", property = "status"),
            @Result(column = "id", property = "roles", javaType = List.class,
                    many = @Many(select = "com.manage.dao.IRoleDao.findRoleByUserId"))
    })
    UserInfo findByUsername(String username);

    @Select("select * from users where username=#{username} and password=#{password}")
    UserInfo findByUsernameAndPassword(@Param("username") String username, @Param("password") String password);

    @Select("select * from users")
    List<UserInfo> findAllUsers();

    @Update("update users set password=#{password} where id=#{id}")
    int updatePassword(@Param("id") String id, @Param("password") String encodedPassword);
}


